using System;

namespace wMobinium.core.test
{
    [NUnit.Framework.TestFixture]
    public class TestCompleteEventArgsTest
    {
        [NUnit.Framework.Test]
        public void EnsureSerializationWorks()
        {
            TestResult testResult = TestResult.NotifySuccess("ensureContactIsEqual", 0, 0);
            TestCompleteEventArgs testCompleteEventArgs =
                new TestCompleteEventArgs("OutlookContacts.Tests", "OutlookContactTest", "ensureContactIsEqual",
                                          testResult);
            testCompleteEventArgs.TimeStamp = DateTime.Parse("Jan/01/2007");

            string serialized = testCompleteEventArgs.Serialize();
            Console.Out.WriteLine(serialized);
            NUnit.Framework.Assert.AreEqual(expectedOutput(), serialized);
        }

        [NUnit.Framework.Test]
        public void EnsureDeserializationWorks()
        {
            TestResult testResult = TestResult.NotifySuccess("ensureContactIsEqual", 0, 0);
            TestCompleteEventArgs expectedTestCompleteEventArgs =
                new TestCompleteEventArgs("OutlookContacts.Tests", "OutlookContactTest", "ensureContactIsEqual",
                                          testResult);
            TestCompleteEventArgs actualTestCompleteEventArgs = TestCompleteEventArgs.Deserialize(expectedOutput());

            NUnit.Framework.Assert.AreEqual(expectedTestCompleteEventArgs, actualTestCompleteEventArgs);
        }

        public string expectedOutput()
        {
            return
                "<?xml version=\"1.0\" encoding=\"utf-16\"?>\r\n<TestCompleteEventArgs xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" assemblyname=\"OutlookContacts.Tests\" classname=\"OutlookContactTest\" methodname=\"ensureContactIsEqual\" timestamp=\"2007-01-01T00:00:00\">\r\n  <testresult>\r\n    <name>ensureContactIsEqual</name>\r\n    <runstate id=\"-1\" value=\"Executed\" />\r\n    <resultstate id=\"0\" value=\"Success\" />\r\n    <failuresite id=\"0\" value=\"None\" />\r\n    <time>0</time>\r\n    <stacktrace />\r\n    <errormessage />\r\n    <assertcount>0</assertcount>\r\n  </testresult>\r\n</TestCompleteEventArgs>";
        }
    }
}